package com.ruoyi.ma.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaMaterialOtherMeasureVo;
import com.ruoyi.ma.domain.bo.MaMaterialOtherMeasureBo;
import com.ruoyi.ma.service.IMaMaterialOtherMeasureService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 其他计量
 *
 * @author llb
 * @date 2024-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/materialOtherMeasure")
public class MaMaterialOtherMeasureController extends BaseController {

    private final IMaMaterialOtherMeasureService iMaMaterialOtherMeasureService;

    /**
     * 查询其他计量列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaMaterialOtherMeasureVo> list(MaMaterialOtherMeasureBo bo, PageQuery pageQuery) {
        return iMaMaterialOtherMeasureService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出其他计量列表
     */
    @SaCheckLogin
    @Log(title = "其他计量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaMaterialOtherMeasureBo bo, HttpServletResponse response) {
        List<MaMaterialOtherMeasureVo> list = iMaMaterialOtherMeasureService.queryList(bo);
        ExcelUtil.exportExcel(list, "其他计量", MaMaterialOtherMeasureVo.class, response);
    }

    /**
     * 获取其他计量详细信息
     *
     * @param otherMeasureId 主键
     */
    @SaCheckLogin
    @GetMapping("/{otherMeasureId}")
    public R<MaMaterialOtherMeasureVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long otherMeasureId) {
        return R.ok(iMaMaterialOtherMeasureService.queryById(otherMeasureId));
    }

    /**
     * 获取其他计量详情信息
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/info")
    public R<MaMaterialOtherMeasureVo> info(MaMaterialOtherMeasureBo bo) {
        return R.ok(iMaMaterialOtherMeasureService.info(bo));
    }

    /**
     * 新增其他计量
     */
    @SaCheckLogin
    @Log(title = "其他计量", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaMaterialOtherMeasureBo bo) {
        return toAjax(iMaMaterialOtherMeasureService.insertByBo(bo));
    }

    /**
     * 修改其他计量
     */
    @SaCheckLogin
    @Log(title = "其他计量", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaMaterialOtherMeasureBo bo) {
        return toAjax(iMaMaterialOtherMeasureService.updateByBo(bo));
    }

    /**
     * 删除其他计量
     *
     * @param otherMeasureIds 主键串
     */
    @SaCheckLogin
    @Log(title = "其他计量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{otherMeasureIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] otherMeasureIds) {
        return toAjax(iMaMaterialOtherMeasureService.deleteWithValidByIds(Arrays.asList(otherMeasureIds), true));
    }
}
